package main

import "fmt"

func main() {
	var n, m int
	var ns, ms []int
	_, _ = fmt.Scan(&n)
	ns = make([]int, n)
	for i := 0; i < n; i++ {
		_, _ = fmt.Scan(&ns[i])
	}
	_, _ = fmt.Scan(&m)
	ms = make([]int, m)
	for i := 0; i < m; i++ {
		_, _ = fmt.Scan(&ms[i])
	}

	res := make([]int, 0)
	i, j := 0, 0
	for i < n && j < m {
		if ns[i] == ms[j] {
			res = append(res, ns[i])
			i++
			j++
		} else if ns[i] > ms[j] {
			i++
		} else {
			j++
		}
	}

	for _, v := range res {
		fmt.Printf("%d ", v)
	}
}
